fix(attach): give every document its own attach-to-process sheet - #96
Merged
Merged
Conversation
The controller was a shared singleton behind `@Dependency(\.attachToProcessViewController)`, so all open documents presented the same instance. Attach To Process is presented as a sheet on the document's root window, and a view controller can only be presented from one window at a time — opening it in a second document while the first still has it up crashes the app. `setupBindings(for:)` also rebinds the shared instance to the second document's view model, so the first document's sheet would keep driving the wrong document even without the crash. Construct the controller per presentation instead, the way every other route in MainCoordinator does. This gives up what 6849d78 bought: the picker no longer remembers the last-selected tab and row across reopens. That state belongs in the view model or AppDefaults, not in a controller instance shared between documents.
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a crash in the document-based app flow by ensuring Attach To Process is presented with a per-document AttachToProcessViewController instance, rather than a shared singleton that could be rebound/presented across multiple windows.
Changes:
- Removed the dependency-injected singleton
AttachToProcessViewControllerand itsDependencyValuesentry. - Updated
MainCoordinatorto construct a freshAttachToProcessViewController()per.attachToProcessroute presentation.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| RuntimeViewerUsingAppKit/RuntimeViewerUsingAppKit/Main/MainCoordinator.swift | Stops resolving a shared controller via @Dependency and instead instantiates a new sheet controller per document route. |
| RuntimeViewerUsingAppKit/RuntimeViewerUsingAppKit/Attach Process/AttachToProcessViewController.swift | Removes the shared singleton and dependency entry that caused cross-document reuse. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| @@ -8,8 +8,6 @@ import DependenciesMacros | |||
| final class AttachToProcessViewController: UXKitViewController<AttachToProcessViewModel> { | |||
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bug
AttachToProcessViewControllerwas held as a shared singleton behind@Dependency(\.attachToProcessViewController).MainCoordinatoris per-document, so every open document resolved and presented the same controller instance.Attach To Process is presented as a sheet on the document's root window (
.presentOnRoot(_, mode: .asSheet)), and a view controller can only be presented from one window at a time — opening it in a second document while the first still has it up crashes the app. Even without the crash,setupBindings(for:)rebinds the shared instance to the second document's view model, so the first document's sheet would keep driving the wrong document.The fix
Construct the controller per presentation, the way every other route in
MainCoordinatordoes. The@DependencyEntryand thefileprivate static let sharedgo away with it.What this gives up
6849d78 introduced the shared instance so the picker would remember the last-selected tab and running row across reopens. That is lost again here. That state belongs in the view model or
AppDefaults, not in a controller instance shared between documents — worth a follow-up, but not at the price of a crash.Related
v2.1.0 has been pulled from the appcast in #95; this is the fix that a 2.1.1 hotfix would carry.